﻿@model IList<AppTracer>
@using Stardust.Data.Monitors
@using NewLife;
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using XCode.Membership;
@using NewLife.Cube;
@{
    var fact = ViewBag.Factory as IEntityFactory;
    var page = ViewBag.Page as Pager;
    var fields = ViewBag.Fields as IList<FieldItem>;
    var ukey = fact.Unique;
    var set = ViewBag.PageSetting as PageSetting;
    var provider = ManageProvider.Provider;
}
<table class="table table-bordered table-hover table-striped table-condensed">
    <thead>
        <tr>
            @if (set.EnableSelect && ukey != null)
            {
                <th class="text-center" style="width:10px;"><input type="checkbox" id="chkAll" title="全选" /></th>
            }
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("ID"))">编号</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Name"))">名称</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("DisplayName"))">显示名</a></th>
            <th class="text-center">每日监控</th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Category"))">类别</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Enable"))">启用</a></th>
            <th class="text-center" title="采样周期。单位秒"><a href="@Html.Raw(page.GetSortUrl("Period"))">采样周期</a></th>
            <th class="text-center" title="最大正常采样数。采样周期内，最多只记录指定数量的正常事件，用于绘制依赖关系"><a href="@Html.Raw(page.GetSortUrl("MaxSamples"))">最大正常采样数</a></th>
            <th class="text-center" title="最大异常采样数。采样周期内，最多只记录指定数量的异常事件，默认10"><a href="@Html.Raw(page.GetSortUrl("MaxErrors"))">最大异常采样数</a></th>
            <th class="text-center" title="超时时间。超过该时间时，当作异常来进行采样，默认5000毫秒"><a href="@Html.Raw(page.GetSortUrl("Timeout"))">超时时间</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Nodes"))">节点集</a></th>
            <th class="text-center">性能</th>
            <th class="text-center">修改日志</th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("UpdateUser"))">更新者</a></th>
            <th class="text-center" style="min-width:134px;"><a href="@Html.Raw(page.GetSortUrl("UpdateTime"))">更新时间</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("UpdateIP"))">更新地址</a></th>
            @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
            {
                <th class="text-center">操作</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (var entity in Model)
        {
            var ap = Stardust.Data.App.FindByName(entity.Name);
            var appId = ap?.Id ?? 0;
            var node = Stardust.Data.Nodes.Node.FindAllByIPs(entity.Nodes?.Split(",")).FirstOrDefault();
            <tr>
                @if (set.EnableSelect && ukey != null)
                {
                    <td class="text-center"><input type="checkbox" name="keys" value="@entity.ID" /></td>
                }
                <td class="text-center">@entity.ID</td>
                <td class="text-center">@entity.Name</td>
                <td class="text-center">@entity.DisplayName</td>
                <td class="text-center"><a href="AppDaystat?appId=@entity.ID" title="该应用每日监控数据">每日监控</a></td>
                <td>@entity.Category</td>
                <td class="text-center">
                    <i class="glyphicon glyphicon-@(entity.Enable ? "ok" : "remove")" style="color: @(entity.Enable ? "green" : "red");"></i>
                </td>
                <td class="text-right">@entity.Period.ToString("n0")</td>
                <td class="text-right">@entity.MaxSamples.ToString("n0")</td>
                <td class="text-right">@entity.MaxErrors.ToString("n0")</td>
                <td class="text-right">@entity.Timeout.ToString("n0")</td>
                <td style="max-width:200px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;" title="@entity.Nodes">
                    @if (node != null)
                    {
                        <a href="../Nodes/NodeData?nodeId=@node.ID">@entity.Nodes</a>
                    }
                    else
                    {
                        <text>@entity.Nodes</text>
                    }
                </td>
                <td>
                    @if (appId > 0)
                    {
                        <a href="../Registry/AppMeter?appId=@appId">性能</a>
                    }
                </td>
                <td><a href="/Admin/Log?category=应用跟踪器&linkId=@entity.ID">修改日志</a></td>
                <td>@entity.UpdateUser</td>
                <td class="text-center">@entity.UpdateTime.ToFullString("")</td>
                <td class="text-center" title="@entity.UpdateIP.IPToAddress()">@entity.UpdateIP</td>
                @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                {
                    <td class="text-center">
                        @await Html.PartialAsync("_List_Data_Action", (Object)entity)
                    </td>
                }
            </tr>
        }
    </tbody>
</table>